import React from 'react';
import { Select } from 'antd';
import { SelectProps } from 'antd/lib/select';
import { MapT, mapToArray } from '@/utils/map';

type Props = SelectProps<any> & { group: MapT };

class SelectGroup extends React.Component<Props> {
  static defaultProps = {
    group: {}
  }

  render() {
    const {
      group,
      ...rest
    } = this.props;
    return (
      <Select {...rest}>
        {mapToArray(group).map((item) => {
          return (
            <Select.Option
              key={item.value}
              value={item.value}
              children={item.label}
            />
          )
        })}
      </Select>
    )
  }
}

export default SelectGroup;
